package org.liquidByte.trafficMustang.androidApp.listview.adapter;

import org.liquidByte.trafficMustang.R;
import org.liquidByte.trafficMustang.androidApp.listview.row.AvaliacaoRow;
import org.liquidByte.trafficMustang.androidApp.listview.row.ListViewRow;
import org.liquidByte.trafficMustang.androidApp.listview.row.RowActionListener;
import org.liquidByte.trafficMustang.androidApp.services.dto.AvaliacaoDTO;

import android.content.Context;
import android.view.View;

public class AvaliacaoRowAdapter extends RowAdapter<AvaliacaoDTO> {
	
	private RowActionListener<AvaliacaoRow> confirmarActionListener;
	private RowActionListener<AvaliacaoRow> editarActionListener;

	public AvaliacaoRowAdapter(Context ctx) {
		super(ctx);
	}

	@Override
	protected int getViewResource() {
		return R.layout.listview_row_avaliacao;
	}

	@Override
	public long getItemId(int position) {
		AvaliacaoDTO avaliacao = (AvaliacaoDTO) this.getItem(position);
		if (avaliacao == null) {
			return 0;
		} else {
			return avaliacao.getId();
		}
	}
	
	public void setConfirmarActionListener(RowActionListener<AvaliacaoRow> listener) {
		this.confirmarActionListener = listener;
	}
	
	public void setEditarActionListener(
			RowActionListener<AvaliacaoRow> editarActionListener) {
		this.editarActionListener = editarActionListener;
	}

	@Override
	protected ListViewRow createRow(View view) {
		AvaliacaoRow row = new AvaliacaoRow(this, view);
		row.setConfirmarActionListener(new RowActionListener<AvaliacaoRow>() {
			@Override
			public void actionPerformed(AvaliacaoRow row) {
				AvaliacaoRowAdapter adapter = AvaliacaoRowAdapter.this;
				if (adapter.confirmarActionListener != null) {
					adapter.confirmarActionListener.actionPerformed(row);
				}
			}
		});
		row.setEditarActionListener(new RowActionListener<AvaliacaoRow>() {
			@Override
			public void actionPerformed(AvaliacaoRow row) {
				AvaliacaoRowAdapter adapter = AvaliacaoRowAdapter.this;
				if (adapter.editarActionListener != null) {
					adapter.editarActionListener.actionPerformed(row);
				}
			}
		});
		return row;
	}
}
